package com.nanfang51g3.ckz.application;

import android.app.Application;
import android.content.pm.PackageInfo;

import com.alipay.euler.andfix.patch.PatchManager;
import com.facebook.stetho.Stetho;
import com.nanfang51g3.ckz.di.ApiModule;
import com.nanfang51g3.ckz.di.AppComponent;
import com.nanfang51g3.ckz.di.DaggerAppComponent;
import com.nanfang51g3.ckz.di.MainModule;
import com.nanfang51g3.ckz.exec.ui.CustomActivityOnCrash;
import com.nanfang51g3.ckz.utils.BuildConfig;
import com.nanfang51g3.ckz.utils.KLog;
import com.nanfang51g3.ckz.utils.SPUtil;
import com.nanfang51g3.ckz.widget.temptyview.TEmptyView;
import com.nanfang51g3.ckz.widget.temptyview.TViewUtil;
import com.squareup.leakcanary.LeakCanary;
import com.umeng.socialize.PlatformConfig;

/**
 * Created by Administrator on 2016/4/12.
 */
public class CkzApplication extends Application {

    public static String VERSION_NAME = "";
    public static String VERSION_CODE = "";
    public static PatchManager mPatchManager;
    private static AppComponent appComponent;

    @Override
    public void onCreate() {
        super.onCreate();
        /**
         * 注解
         */
        appComponent = DaggerAppComponent
                .builder()
                .mainModule(new MainModule(this))
                .apiModule(new ApiModule(getApplicationContext()))
                .build();
        LeakCanary.install(this);
        //微信
        PlatformConfig.setWeixin("wxc061b596c32e1d5c", "5a5aaf41df3db53b3105b25a62d74b49");
        PlatformConfig.setQQZone("1105318647", "Y02XrRzPdGbLbR44");
        //捕抓异常崩溃
        CustomActivityOnCrash.install(this);
        KLog.init(BuildConfig.LOG_DEBUG_TRUE);
//        //初始化网络调试器 运行app 打开Chrome输入chrome://inspect/#devices
       Stetho.initializeWithDefaults(this);
        TViewUtil.EmptyViewBuilder emptyViewConfig = TViewUtil.EmptyViewBuilder.getInstance(getApplicationContext())
                .setShowText(true)
                .setEmptyText("NO DATA")
                .setShowButton(false)
                .setShowIcon(true);
        TEmptyView.init(emptyViewConfig);
        try {
            //热修复功能暂未使用上线
            //获取当前版本号
            PackageInfo packageInfo = this.getPackageManager().getPackageInfo(this.getPackageName(), 0);
            SPUtil.putAndApply(this,"version_code",packageInfo.versionCode+"");
            SPUtil.putAndApply(this,"version_name",packageInfo.versionName+"");
            VERSION_NAME = packageInfo.versionName;
            VERSION_CODE = packageInfo.versionCode+"";
        } catch (Exception e) {
            KLog.i("Evd", "e=" + e.toString());
        }
        /* initAndFix();*/
    }

    public void initAndFix() {
        //构建热修复管理器
        mPatchManager = new PatchManager(this);
        //初始化热修复器并载入版本号
        mPatchManager.init(VERSION_NAME);
        KLog.i("Evd", "init...");
        //加载热修复文件
        mPatchManager.loadPatch();
        KLog.i("Evd", "loadPatch...");
    }
    public static AppComponent getAppComponent() {
        return appComponent;
    }

}
